package com.corn.turorial.spring.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @author : Jim Wu
 * @version 1.0
 * @function :
 * @since : 2021/1/13 11:29
 */

@Aspect
@Component
public class AopPointCut {
    @Pointcut("execution(public * com.corn.turorial.spring.aop.AopTestService.*(..))")
    private void pointCut() {
    }

    @Before(value = "pointCut()")
    public void before() {
        System.out.println("前置通知...");
    }

    @Around(value = "pointCut()")
    public Object around(ProceedingJoinPoint point) throws Throwable {
        System.out.println("环绕前通知..");
        Object returnData = null;
//        returnData = point.proceed();

        try {
            returnData = point.proceed();
        } catch (Throwable throwable) {
            System.out.println("方法出现了异常!");
        }
        System.out.println("环绕后通知..");
        return returnData;
    }

    @After(value = "pointCut()")
    public void after() {
        System.out.println("后置通知...");
    }

    @AfterReturning(value = "pointCut()")
    public void afterReturning() {
        System.out.println("返回通知...");
    }

    @AfterThrowing(value = "pointCut()")
    public void afterThrowing() {
        System.out.println("异常通知...");
    }
}
